//
//  DessertCollectionViewCell.m
//  吃货·上海
//
//  Created by lanou on 15/11/24.
//  Copyright © 2015年 濮亚军. All rights reserved.
//

#import "DessertCollectionViewCell.h"
#import "PrefixHeader.pch"
#import "UIImageView+WebCache.h"
@interface DessertCollectionViewCell ()

@property(nonatomic,strong)UIImageView *icon;//菜谱图
@property(nonatomic,strong)UILabel *infoLable;//菜谱简介
@property(nonatomic,strong)UIImageView *replyView;
@property(nonatomic,strong)UIImageView *likeView;
@property(nonatomic,strong)UIImageView *favView;
@property(nonatomic,strong)UILabel *replyLable;//评论
@property(nonatomic,strong)UILabel *likeLable;//点赞
@property(nonatomic,strong)UILabel *favouriteLable;//喜欢
@property(nonatomic,strong)UIImageView *avatar;
@property(nonatomic,strong)UILabel *nameLable;

@end

@implementation DessertCollectionViewCell


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
//        菜谱图片
        self.icon = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height * 9 /16)];
        [self.contentView addSubview:_icon];
        
        
//        菜谱简介
        self.infoLable = [[UILabel alloc]initWithFrame:CGRectMake(5, self.icon.frame.size.height + 5, frame.size.width - 5, frame.size.height * 2 / 16)];
        self.infoLable.numberOfLines = 0;
        self.infoLable.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_infoLable];
        
        
        CGFloat lableY = self.icon.frame.size.height + self.infoLable.frame.size.height + 15;
        CGFloat width = frame.size.width / 6;
        CGFloat height = frame.size.height / 16;
//        评论
        self.replyLable = [[UILabel alloc]initWithFrame:CGRectMake(5 + self.replyView.frame.size.width,lableY, width * 5 / 4, height)];
        self.replyLable.textAlignment = NSTextAlignmentRight;
        self.replyLable.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:_replyLable];
        self.replyView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 2, width / 2, height - 5)];
        self.replyView.image = [UIImage imageNamed:@"reply"];
        [self.replyLable addSubview:_replyView];
        
        
//        点赞
        self.likeLable = [[UILabel alloc]initWithFrame:CGRectMake(self.replyLable.frame.size.width + 10, lableY, width * 5 / 4, height)];
        self.likeLable.textAlignment = NSTextAlignmentRight;
        self.likeLable.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:_likeLable];
        self.likeView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 2, width / 2, height - 5)];
        self.likeView.image = [UIImage imageNamed:@"like"];
        [self.likeLable addSubview:_likeView];
        
        
//        喜欢
        
        self.favouriteLable = [[UILabel alloc]initWithFrame:CGRectMake(self.replyLable.frame.size.width + self.likeLable.frame.size.width + 20, lableY, width * 5 / 4, height)];
        self.favouriteLable.textAlignment = NSTextAlignmentRight;
        self.favouriteLable.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:_favouriteLable];
        
        self.favView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, width / 2, height)];
        self.favView.image = [UIImage imageNamed:@"fav"];
        [self.favouriteLable addSubview:_favView];
        
//        添加一条间隔线
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, lableY + 30, frame.size.width, 1)];
        line.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:line];
        
        
//        作者👤
        self.avatar = [[UIImageView alloc]initWithFrame:CGRectMake(10, lableY + 35, height * 2, height * 2)];
        self.avatar.layer.masksToBounds = YES;
        self.avatar.layer.cornerRadius = height;
        [self.contentView addSubview:_avatar];
        self.nameLable = [[UILabel alloc]initWithFrame:CGRectMake(60, lableY + 35, frame.size.width - 65, height * 2)];
        self.nameLable.font = [UIFont systemFontOfSize:11];
        self.nameLable.numberOfLines = 0;
        [self.contentView addSubview:_nameLable];
        
    }
    return self;
}


- (void)setModel:(DessertModel *)model
{
    _model = model;
    [self.icon sd_setImageWithURL:[NSURL URLWithString:model.path]];
    self.infoLable.text = model.msg;
    self.replyLable.text = [NSString stringWithFormat:@"%ld",model.reply_count];
    self.likeLable.text = [NSString stringWithFormat:@"%ld",model.like_count];
    self.favouriteLable.text = [NSString stringWithFormat:@"%ld",model.favorite_count];
    [self.avatar sd_setImageWithURL:[NSURL URLWithString:model.avatar]];
    self.nameLable.text = model.username;
    
}


@end
